package com.woniuxy.service.impl;

import com.woniuxy.entity.*;
import com.woniuxy.mapper.*;
import com.woniuxy.service.FoodService;
import com.woniuxy.vo.CampVO;
import com.woniuxy.vo.FoodCommentlVO;
import com.woniuxy.vo.FoodOrderVO;
import com.woniuxy.vo.FoodVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author Hgx
 * @ClassName FoodServiceImpl
 * @create 2020-06-02 11:50
 */
@Service
public class FoodServiceImpl implements FoodService {

    @Resource
    private FoodMapper foodMapper;
    @Resource
    private FoodOrderMapper foodOrderMapper;
    @Resource
    private ImgMapper imgMapper;
    @Resource
    private CampMapper campMapper;
    @Resource
    private FoodCommentMapper foodCommentMapper;
    /**
     * 条件分页查询
     * @param map
     * @return
     */
    @Override
    public List<FoodVO> pageSelectFoodByExample(Map<String, Object> map) throws Exception{
        return  foodMapper.pageSelectFoodByExample(map);
    }

    /**
     * 统计总条数
     * @param map
     * @return
     */
    @Override
    public int countFoodByExample(Map<String, Object> map) throws Exception{
        return foodMapper.countFoodByExample(map);
    }

    /**
     * 美食管理的菜品的信息的更新
     * @param food
     * @return
     */
    @Override
    public int updateFood(Food food)throws Exception{
        return foodMapper.updateByPrimaryKeySelective(food);
    }

    /**
     * 美食管理的菜品的信息的删除
     * @param foodId
     * @return
     */
    @Override
    public int deleteFood(Integer foodId) throws Exception{
        return foodMapper.deleteByPrimaryKey(foodId);
    }

    /**
     * 美食订单条件分页查询
     * @param map
     * @return
     */
    @Override
    public List<FoodOrderVO> selectFoodOrderByExample(Map<String, Object> map) throws Exception{
        return foodOrderMapper.selectFoodOrderByExample(map);
    }

    /**
     * 美食订单统计总条数
     * @param map
     * @return
     */
    @Override
    public int countFoodOrder(Map<String, Object> map) throws Exception{
        return foodOrderMapper.countFoodOrder(map);
    }

    /**
     * 添加美食返回主键
     * @param food
     * @return
     */
    @Override
    public int insertFoodReturnFoodId(Food food)throws Exception{
        return foodMapper.insertFoodReturnFoodId(food);
    }

    /**
     * 在数据库中新增图片地址
     * @param foodId
     * @param url
     * @return
     */
    @Override
    public int insertFoodImg(int foodId, String url) throws Exception{
        Img img = new Img();
        img.setOtherId(foodId);
        img.setUrl(url);
        img.setTypeId(4);
        return imgMapper.insertSelective(img);
    }

    /**
     * 在新增美食中通过选择城市选择营地
     * @param cityId
     * @return
     */
    @Override
    public List<Camp> selectCampByCityName(int cityId) {
        List<Camp> camps = campMapper.selectCampByCityName(cityId);
        return camps;
    }

    /**
     *
     * @param res
     * @return
     */
    @Override
    public int insertFoodAddress(int res,int campId) {
        Food food = new Food();
        food.setFoodId(res);
        Camp camp = campMapper.selectByPrimaryKey(campId);
        food.setAddress(camp.getAddress());
        int i = foodMapper.updateByPrimaryKeySelective(food);
        return i;
    }

    /**
     * ele
     * 查询所有美食的评论
     * @return
     */
    @Override
    public List<FoodCommentlVO> selectAllFoodCommentlVO() {
        return  foodMapper.selectAllFoodCommentlVO();
    }

    /**
     * 评论的初始查询
     * @param map
     * @return
     */
    @Override
    public List<FoodCommentlVO> selectFoodCommentByExample(Map<String, Object> map) {
        return foodCommentMapper.selectFoodCommentByExample(map);
    }

    /**
     * 评论的初始查询统计
     * @param map
     * @return
     */
    @Override
    public int countFoodCommentByExample(Map<String, Object> map) {
        return foodCommentMapper.countFoodCommentByExample(map);
    }
}
